﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TrainingsPlaces>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TrainingsPlaces>>" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsPlaces";
                                        settings.KeyFieldName = "IdTrainingsPlace";
                                        settings.CallbackRouteValues =
                                            new { Controller = "TC", Action = "TrainingsPlacesPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.NameEn;
                                            column.FieldName = "NameEn";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.NameRu;
                                            column.FieldName = "NameRu";
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCenter";
                                            column.Caption = Resourses.TrainingsCenters;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var centersCol = new CRM.Database.Model.TrainingsCentersCollection();
                                                comboBoxProperties.DataSource = centersCol.TrainingsCentersList;
                                                //comboBoxProperties.DataSource = DB.TrainingsCenters;
                                                comboBoxProperties.TextField = "NameRu";
                                                comboBoxProperties.ValueField = "IdTrainingsCenter";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCity";
                                            column.Caption = Resourses.TrainingsCity;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var citiesCol = new CRM.Database.Model.TrainingsCitiesCollection();
                                                comboBoxProperties.DataSource = citiesCol.TrainingsCitiesList;
                                                //comboBoxProperties.DataSource = DB.TrainingsCities;
                                                comboBoxProperties.TextField = "TrainingsCityName";
                                                comboBoxProperties.ValueField = "IdTrainingsCity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Address;
                                            column.FieldName = "Address";
                                        });
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Capacity;
                                            column.FieldName = "Capacity";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.CommentsRu;
                                            column.FieldName = "CommentsRu";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.CommentsEn;
                                            column.FieldName = "CommentsEn";
                                        });
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.IsActive;
                                            column.FieldName = "IsActive";
                                            column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "AcceptanceFileName";
                                            column.Caption = Resourses.TrainingsFileTemplate;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var confCol = new CRM.Database.Model.ConfigurationsCollection();
                                                comboBoxProperties.DataSource = confCol.TrainingsAcceptanceFileNames;
                                                //comboBoxProperties.DataSource = DB.TrainingsAcceptanceFileNames;
                                                //comboBoxProperties.ValueField = "AcceptanceFileName";
                                                comboBoxProperties.ValueType = typeof(string);
                                            }
                                        });

                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "TC", Action = "TrainingsPlacesPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TC", Action = "TrainingsPlacesPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TC", Action = "TrainingsPlacesPartialDelete" };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                        
                                    })
       .Bind(Model).GetHtml();
%>

